import processing.core.PApplet;

public class button {
	public boolean on = false;
	boolean hover = false;
	boolean pressing = false;
	boolean toggle = false;
	boolean selected = false;
	boolean resizeSel = false;
	boolean rename = false;
	RRect roundRect;

	int x = 100;
	int y = 150;
	int w = 100;
	int h = 60;
	int corner = 8;
	int[] _color = { 210, 210, 210, 255 };
	String label = "default";

	PApplet parent;

	public button() {
		
	}
	
	public button(PApplet p) {
		parent = p;
		roundRect = new RRect(p);
	}

	void init(int x, int y, int w, int h, String label, boolean toggle) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.label = label;
		this.toggle = toggle;
		display();
	}
	
	void init(int x, int y, int w, int h, String label, boolean toggle, boolean on) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.label = label;
		this.toggle = toggle;
		this.on = on;
		display();
	}

	void display() {
		if (Main.editMode && selected) {
			parent.fill(110, 110, 110, 255);
			roundRect.rrect(x, y, w, h, corner);
			parent.fill(255);
			parent.text(label, (float) (x + w / 6.), (float) (y + h * 5 / 6.));
		} else {
			if (on) {
				parent.fill(170, 170, 170, 255);
				roundRect.rrect(x, y, w, h, corner);
				parent.fill(255);
				parent.text(label, (float) (x + w / 6.), (float) (y + h * 5 / 6.));
			} else if (hover) {
				parent.fill(230, 230, 230, 255);
				roundRect.rrect(x, y, w, h, corner);
				parent.fill(0);
				parent.text(label, (float) (x + w / 6.), (float) (y + h * 5 / 6.));
			} else {
				parent.fill(_color[0], _color[1], _color[2], _color[3]);
				roundRect.rrect(x, y, w, h, corner);
				parent.fill(0);
				parent.text(label, (float) (x + w / 6.),
						(float) (y + h * 5 / 6.));
			}
			if (pressing) {
				parent.fill(170, 170, 170, 255);
				roundRect.rrect(x, y, w, h, corner);
				parent.fill(255);
				parent.text(label, (float) (x + w / 6.),
						(float) (y + h * 5 / 6.));
			}
		}
	}
	
	Object[] toObj() {
		Object[] object = new Object[12];
		object[0]=x;
		object[1]=y;
		object[2]=w;
		object[3]=h;
		object[4]=corner;
		object[5]=_color[0];
		object[6]=_color[1];
		object[7]=_color[2];
		object[8]=_color[3];
		object[9]=label;
		object[10]=on;
		object[11]=toggle;
		return object;
	}
}

